/* Copyright (C) 2008, 2009, 2010 Faindu GmbH, Switzerland.
* All Rights Reserved. The following is Source Code and is subject to all restrictions 
* on such code as contained in the license accompanying this project. */
package blocstac.editimage.base
{

import blocstac.util.Print;

import flash.display.BitmapData;

import flexunit.framework.TestCase;

public class ViewModel_imageLargerThanComponentByTest extends TestCase
{

    //==========================================================================
    //
    //  Test set up and tear down
    //
    //--------------------------------------------------------------------------  
	private var viewModel:ViewModel
	private var imageModel:ImageModel
	private var imageData:BitmapData
	
	override public function setUp(): void {
		imageModel = new ImageModel()
		viewModel = new ViewModel(imageModel)
		imageData = new BitmapData(10, 15)
		
		imageModel.updateImageData(imageData)
		viewModel.maxComponentWidthInContainer(5)
	}
	
	override public function tearDown():void {
	}
	
    //==========================================================================
    //
    //  Tests
    //
    //--------------------------------------------------------------------------  
	[Test]
	public function test_imageIsWiderThanComponent(): void {
		assertTrue(viewModel.imageIsWiderThanComponent)
	}
	
	[Test]
	public function test_rotationMatrix(): void {	
		imageModel.updateImageData(imageData)
		imageModel.angle = Math.PI / 2 
		
		assertEquals("[a=0, b=1, c=-1, d=0, tx=0, ty=0]", Print.matrix(viewModel.rotationMatrix, 8))
	}
	
	[Test]
	public function test_rotationMatrix_interactionEnds(): void {	
		imageModel.angle = Math.PI / 2 
		viewModel.interactionEnds()
		
		assertEquals("[a=0, b=1, c=-1, d=0, tx=7.5, ty=0]", Print.matrix(viewModel.rotationMatrix, 8))
	}

	[Test]
	public function test_imageCenterInImageComp(): void {	
		imageModel.editedScaleX = 2
		imageModel.editedScaleY = 3
		assertEquals(5, viewModel.imageCenterInImageComp.x)
		assertEquals(11.25, viewModel.imageCenterInImageComp.y)
	}

	[Test]
	public function test_brImageCornerInRotationCompUnscaled(): void {	
		imageModel.editedScaleX = 2
		imageModel.editedScaleY = 3
		assertEquals(10, viewModel.brImageCornerInRotationCompUnscaled.x)
		assertEquals(15, viewModel.brImageCornerInRotationCompUnscaled.y)
	}
	
	[Test]
	public function test_imageMatrix(): void {	
		assertEquals("(a=0.5, b=0, c=0, d=0.5, tx=0, ty=0)", viewModel.imageMatrix.toString())
		
		imageModel.editedScaleX = 2
		imageModel.editedScaleY = 3
		assertEquals("(a=1, b=0, c=0, d=1.5, tx=0, ty=0)", viewModel.imageMatrix.toString())
	}
	
	[Test]
	public function test_componentWidth_and_Height_simple(): void {	
		assertEquals(5, viewModel.componentWidth)
		assertEquals(7.5, viewModel.componentHeight)
	}
	
	[Test]
	public function test_componentWidth_and_Height_with_rotation(): void {	
		imageModel.updateImageData(imageData)
		imageModel.angle = Math.PI / 2 
		viewModel.interactionEnds()
		
		assertEquals(7.5, viewModel.componentWidth) // flipped
		assertEquals(5, viewModel.componentHeight)
	}
}
}